const express = require('express')//引入express模块
const path = require('path')//引入路径模块
const DetectUser = require('../js/DetectUser')//引入自定义模块
const router = express.Router()//实例化路由对象
router.use(express.urlencoded({extended:false})) 

router.get('/', (req, res) => {
    let filepath = path.join(__dirname, '../index.html')//绝对路径首页拼接起来
    res.sendFile(filepath)//响应 filepath 路径的文件
})
router.get('/view/login.html', (req,res,next) => {
   
    let filepath = path.join(__dirname, '../view/login.html')
    console.log(filepath);
    next(filepath)
})
router.get('/view/register.html', (req, res,next) => {
    let filepath = path.join(__dirname, '../view/register.html')
    next(filepath)
})


router.post('/view/loginp', (req, res) => {
    console.log(req.body);
    res.send(DetectUser.login(req.body))//接受登录url后的参数
})
router.post('/view/registerp', (req, res) => {
    console.log(req.body);
    res.send(DetectUser.register(req.body))//接受注册url后的参数
})

router.use( (err,req,res,next)=>{
    // res.send('到达了4个参数的这个中间件')
    res.sendFile(err)
} )

module.exports = router//暴露router对象